package blah;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import javax.swing.SwingUtilities;

/**
 * <pre>
 * loop
 *   await PropertyChangeEvent(_, value) ->
 *     emit PropertyChangeEvent(Echo, value)
 * </pre>
 */
public class EchoBean implements PropertyChangeListener {
      
  private PropertyChangeSupport listeners = new PropertyChangeSupport(this);

  public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
    listeners.addPropertyChangeListener(l);
  }

  public synchronized void removePropertyChangeListener(PropertyChangeListener l) {
    listeners.removePropertyChangeListener(l);
  }

  protected void fireEcho(Object value) {
//  	System.out.println("firing event");
    listeners.firePropertyChange(new PropertyChangeEvent(this, "Echo", null, value));
//    System.out.println("done firing");
  }
  
  public void propertyChange(final PropertyChangeEvent event) {
//  	System.out.println("getting event");
  	SwingUtilities.invokeLater(new Runnable() {
  		public void run() { 			
  			fireEcho(event.getNewValue());
  		}
  	});
//  	System.out.print("processed event"); 
  }
}
